package com.wolf.gulimall.product.web;


import com.wolf.gulimall.product.entity.CategoryEntity;
import com.wolf.gulimall.product.service.CategoryService;
import com.wolf.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 首页
     *
     * @return
     */
    @GetMapping({"/", "/index.html"})
    public String indexPage(Model model) {
        //查询一级分类
        List<CategoryEntity> categoryEntityList = categoryService.getLevelOneCategory();
        model.addAttribute("categoryEntityList", categoryEntityList);
        return "index";
    }

    /**
     * 查询所有分类信息
     * @return 分类信息
     */
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson() {
        return categoryService.getCatalogJsonByCache();

    }


}
